package org.workplicity.cia.ui.honeycomb;

import org.workplicity.cia.ui.honeycomb.MainFrameActivity.MyTabListener;
import org.workplicity.cia.ui.honeycomb.fragments.CatchEditFragment;
import org.workplicity.cia.ui.honeycomb.fragments.CommentEditFragment;
import org.workplicity.cia.ui.honeycomb.fragments.HandoffEditFragment;
import org.workplicity.cia.ui.honeycomb.fragments.HandoffFragment;
import org.workplicity.cia.ui.honeycomb.fragments.LinkEditFragment;
import org.workplicity.cia.ui.honeycomb.fragments.LogEditFragment;
import org.workplicity.cia.ui.honeycomb.fragments.LogFragment;

import android.app.ActionBar;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.app.ActionBar.Tab;
import android.os.Bundle;

public class ElogEditActivity extends Activity {

	 @Override
	 public void onCreate(Bundle savedInstanceState) {
		 super.onCreate(savedInstanceState);

	        setContentView(R.layout.elogedit);
	        
	        ActionBar bar = getActionBar();
	        

	        bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
	        
	        ActionBar.Tab tabA = bar.newTab().setText("Log");
	        ActionBar.Tab tabB = bar.newTab().setText("Handoff");
	        ActionBar.Tab tabC = bar.newTab().setText("Link");
	        ActionBar.Tab tabD = bar.newTab().setText("Comments");
	        ActionBar.Tab tabE = bar.newTab().setText("Catch");

	        Fragment logEditFrag = new LogEditFragment();
	        Fragment handoffEditFrag = new HandoffEditFragment();
	        Fragment linkEditFrag = new LinkEditFragment();
	        Fragment commentEditFrag = new CommentEditFragment();
	        Fragment catchEditFrag = new CatchEditFragment();
	        
	        tabA.setTabListener(new MyTabListener(logEditFrag));
	        tabB.setTabListener(new MyTabListener(handoffEditFrag));
	        tabC.setTabListener(new MyTabListener(linkEditFrag));
	        tabD.setTabListener(new MyTabListener(commentEditFrag));
	        tabE.setTabListener(new MyTabListener(catchEditFrag));
	        
	        bar.addTab(tabA);
	        bar.addTab(tabB);
	        bar.addTab(tabC);
	        bar.addTab(tabD);
	        bar.addTab(tabE);
	 }
	 
	 
	 protected class MyTabListener implements ActionBar.TabListener {
	        private Fragment myFragment;

	        // Called to create an instance of the listener when adding a new tab
	        public MyTabListener(Fragment fragment) {
	            myFragment = fragment;
	        }

	        public void onTabSelected(Tab tab, FragmentTransaction ft) {
	            ft.add(R.id.logfragments, myFragment, null);
	        }

	        public void onTabUnselected(Tab tab, FragmentTransaction ft) {
	            ft.remove(myFragment);
	        }

	        public void onTabReselected(Tab tab, FragmentTransaction ft) {
	            // do nothing
	        }

	    }
}
